#include "dbusClient.hpp"
#include <sdbus-c++/IConnection.h>
#include <sdbus-c++/IProxy.h>
#include <tuple>

const static char* InterfaceName="org.HBTY.WorkDataManager";

dbusClient::dbusClient()
{
  auto session=sdbus::createSessionBusConnection();
  proxy=sdbus::createProxy(*session,"org.HBTY.WorkDataManager","/org/HBTY/WorkDataManager");
}

dbusClient::~dbusClient()
{

}

std::vector<long> dbusClient::SearchHandleFinishItem(long taskID)
{
  std::vector<long> res;
  proxy->callMethod("GetRecordFinishHandleListWithTask").onInterface(InterfaceName).withArguments(taskID).storeResultsTo(res);
  return res;
}

std::vector<long> dbusClient::GetTaskList()
{
  std::vector<long> res;
  proxy->callMethod("GetTaskIDList").onInterface(InterfaceName).storeResultsTo(res);
  return res;
}

std::tuple<std::string,std::string> dbusClient::GetTaskInfo(long taskId)
{
  std::string name,createTime;
  proxy->callMethod("GetTaskInf").onInterface(InterfaceName).withArguments(taskId).storeResultsTo(name,createTime);
  return std::make_tuple(name,createTime);
}

std::tuple<long,std::string,std::string> dbusClient::GetItemInfo(long itemid)
{
  long stuid,taskid;
  std::string createTime;
  bool smplStatus,recordFinish;
  std::string path;
  proxy->callMethod("GetRecordInf").onInterface(InterfaceName).withArguments(itemid).storeResultsTo(stuid,taskid,createTime,smplStatus,recordFinish);
  proxy->callMethod("GetRecordPath").onInterface(InterfaceName).withArguments(itemid).storeResultsTo(path);
  return std::make_tuple(stuid,createTime,path);
}
